//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _ACTIONDISPATCHER_H
#define _ACTIONDISPATCHER_H
//
#include <QObject>
#include <QHash>
#include "actionstate.h"
//
class QSignalMapper;
class QAction;
class ActionDispatcher:public QObject
{
   Q_OBJECT
   Q_DISABLE_COPY(ActionDispatcher)
   friend class ActionState;
//construction
public:
   ActionDispatcher(QObject *parent=0);
   ~ActionDispatcher();
//slots
protected slots:
   void triggered(bool checked);
//management
public:
   void register_action(QAction *action);
   void unregister_action(QAction *action);
//implementation
private:
   typedef QList<ActionState*> HandlerList;
   typedef QHash<QAction*,HandlerList> HandlerHash;
   HandlerHash handler;
   QSignalMapper *mapper;
   void attach_handler(ActionState &state);
   void detach_handler(ActionState &state);
   void activate_handler(ActionState &state);
   void deactivate_handler(ActionState &state);
//DefaultHandler
private:
   class DefaultHandler;
};
//
#endif
